<template>
    <div>
      <div class="top-panel">
        <el-card>
          <el-form :model="searchForm" label-width="70px" label-position="right">
            <el-row>
              <el-col :span="5" :xs="24">
                <el-form-item label="志愿者编号" label-width="100px">
                  <el-input
                    class="password-input"
                    v-model="searchForm.userIdFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter="loadDataList"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :xs="24">
                <el-form-item label="姓名">
                  <el-input
                    class="password-input"
                    v-model="searchForm.nameFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter="loadDataList"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :xs="24">
                <el-form-item label="活动编号" label-width="100px">
                  <el-input
                    class="password-input"
                    v-model="searchForm.activityIdFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter="loadDataList"
                  >
                  </el-input>
                </el-form-item>

              </el-col>
              <el-col :span="5" :xs="24">
                <el-form-item label="活动名称" label-width="100px">
                  <el-input
                    class="password-input"
                    v-model="searchForm.activityNameFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter="loadDataList"
                  >
                  </el-input>
                </el-form-item>

              </el-col>

              <el-col :span="4" :style="{ paddingLeft: '10px' }">
                <el-button type="success" @click="loadDataList()"
                  >查询
                </el-button>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
      </div>
      <el-card class="table-data-card">
        <template #header>
          <span style="color:rgb(29, 32, 136);font-weight: bolder;">活动评论记录</span>
        </template>
        <Table
          ref="tableInfoRef"
          :columns="columns"
          :fetch="loadDataList"
          :dataSource="tableData"
          :options="tableOptions"
          :extHeight="tableOptions.extHeight"
        >
          <template #slotOperation="{ index, row }">
            <div
            v-if="userInfo.roleType==1"
              class="row-op-panel">
              <a
                class="a-link"
                href="javascript:void(0)"
                @click.prevent="delRating(row)"
                >删除</a
              >
            </div>
          </template>
        </Table>
      </el-card>


    </div>
  </template>

  <script setup>
  import { getCurrentInstance, nextTick, ref } from "vue";
  import { useRouter, useRoute } from "vue-router";

  const { proxy } = getCurrentInstance();

  const userInfo = ref(proxy.VueCookies.get("userInfo") || {});
  const router = useRouter();
  const route = useRoute();
  const api = {
    loadDataList: "/rating/loadRatingList",
    delRating:"/rating/deleteRatingInfo",
  };
  const searchForm = ref({});

  const tableData = ref({});
  const tableOptions = ref({
    extHeight: 125,
  });

  const columns = [
  {
      label: "序号",
      prop: "id",
    },
    {
      label: "志愿者编号",
      prop: "userId",
    },
    {
      label: "姓名",
      prop: "name",
    },
    {
      label: "活动编号",
      prop: "activityId",
    },
    {
      label: "活动名称",
      prop: "activityName",
    },

    {
      label: "内容",
      prop: "comment",
    },
    {
      label: "评分",
      prop: "rating",
    },
    {
      label: "评论时间",
      prop: "createTime",
    },
    {
      label: "操作",
      prop: "operation",
      scopedSlots: "slotOperation",
      width:160
    },
  ];

  const tableInfoRef = ref();

  const loadDataList = async () => {
    let params = {
      pageNo: tableData.value.pageNo,
      pageSize: tableData.value.pageSize,
    };
    Object.assign(params, searchForm.value);
    let result = await proxy.Request({
      url: api.loadDataList,
      params: params,
    });
    if (!result) {
      return;
    }
    Object.assign(tableData.value, result.data);
  };

  //删除
  const delRating = (data) => {
    proxy.Confirm(`确定要删除【${data.name}】的评论吗？`, async () => {
      let result = await proxy.Request({
        url: api.delRating,
        params: {
            id: data.id,
        },
      });
      if (!result) {
        return;
      }
      proxy.Message.success("操作成功");
      loadDataList();
    });
  };







  </script>

  <style lang="scss" scoped>
  .detail-tree-panel {
    height: calc(100vh - 273px);
    overflow: auto;
    width: 100%;
  }
  </style>
